program define createvarspub
* Create dummies to indicate affiliation to university
*(any institution in the univ)
egen ucoimbra=anymatch(univ*), values(10)
egen ulisboa=anymatch(univ*), values(28)
egen uminho=anymatch(univ*), values(33)
egen unova=anymatch(univ*), values(39)
egen uporto=anymatch(univ*), values(43)
egen ucp=anymatch(univ*), values(77)
egen utad=anymatch(univ*), values(143)
egen uaveiro=anymatch(univ*), values(146)
egen uevora=anymatch(univ*), values(150)
egen ualgarve=anymatch(univ*), values(167)
egen iscte=anymatch(univ*), values(231)
egen umadeira=anymatch(univ*), values(261)
egen ubi=anymatch(univ*), values(361)
egen uacores=anymatch(univ*), values(139)
egen bp=anymatch(affil*), values(2)
egen foreign=anymatch(affil*_nation), values(0)
egen national=anymatch(affil*_nation), values(1)
replace foreign=. if affil1==168 | affil1==191
replace national=. if affil1==168 | affil1==191
gen pfaonly=(portnat==1&national==0&foreign==1)

local vars national ucoimbra ulisboa uminho /// 
unova uporto ucp utad uaveiro uevora ualgarve ///
iscte umadeira ubi uacores bp pfaonly portnat

foreach var in `vars'{
bys article_id: egen t`var'=total(`var')
replace t`var'=(t`var'>0 & t`var'<.)
	}

gen tportpub=tucoimbra|tulisboa|tuminho|tunova|tuporto|tucp|tutad| ///
tuaveiro|tuevora|tualgarve|tiscte|tumadeira|tubi|tuacores|tbp

label variable ucoimbra "Author has at least one affiliation to Coimbra U"
label variable ulisboa "Author has at least one affiliation to Lisboa U"
label variable uminho "Author has at least one affiliation to Minho U"
label variable unova "Author has at least one affiliation to Nova U"
label variable uporto "Author has at least one affiliation to Porto U"
label variable ucp "Author has at least one affiliation to UCP"
label variable utad "Author has at least one affiliation to UTAD"
label variable uaveiro "Author has at least one affiliation to Aveiro U"
label variable uevora "Author has at least one affiliation to Evora U"
label variable ualgarve "Author has at least one affiliation to Algarve U"
label variable iscte "Author has at least one affiliation to ISCTE"
label variable umadeira "Author has at least one affiliation to Madeira U"
label variable ubi "Author has at least one affiliation to UBI"
label variable uacores "Author has at least one affiliation to Acores U"
label variable bp "Author has at least one affiliation to Banco de Portugal"
label variable foreign "Author has at least one foreign affiliation"
label variable national "Author has at least one Portuguese affilation"
label variable tnational "Article has at least one author with Portuguese affiliation"
label variable tucoimbra "Article has at least one author affiliated with Coimbra U"
label variable tulisboa "Article has at least one author affiliated with Lisboa U"
label variable tuminho "Article has at least one author affiliated with Minho U"
label variable tunova "Article has at least one author affiliated with Nova U"
label variable tuporto "Article has at least one author affiliated with Porto U"
label variable tucp "Article has at least one author affiliated with UCP"
label variable tutad "Article has at least one author affiliated with UTAD"
label variable tuaveiro "Article has at least one author affiliated with Aveiro U"
label variable tuevora "Article has at least one author affiliated with Evora U"
label variable tualgarve "Article has at least one author affiliated with Algarve U"
label variable tiscte "Article has at least one author affiliated with ISCTE"
label variable tumadeira "Article has at least one author affiliated with Madeira U"
label variable tubi "Article has at least one author affiliated with UBI"
label variable tuacores "Article has at least one author affiliated with Acores U"
label variable tbp "Article has at least one author affiliated with Bank of Portugal"
label variable tportpub "Article has at least one author aff with a public uni, UCP or BdP"
label variable tportnat "Article has at least one Portuguese author"
label variable pfaonly "Portuguese author has only foreign affiliations"
label variable tpfaonly "Article has Portuguese author with foreign affiliations only"
end
